<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Expires" CONTENT="0">
    <meta http-equiv="Cache-Control" content="no-siteapp,no-transform,no-store, no-cache, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <link rel="shortcut icon" href="./../../../favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="./../../../static/css/font.css">
    <link rel="stylesheet" href="./../../../static/css/weadmin.css">
    <link rel="stylesheet" href="./../../../lib/jqueryZtree/3.5.12/css/zTreeStyle/zTreeStyle.min.css">
    <link rel="stylesheet" href="./../../../static/js/utils/easyUi/easyui.css">
    <script type="text/javascript" src=".//lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./../../../lib/jquery/jquery-1.7.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="./../../../lib/easyUi/jquery.easyui.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="./../../../lib/jqueryZtree/3.5.12/js/jquery.ztree.all-3.5.js"
            charset="utf-8"></script>
    <style type="text/css">
        .ztree li span.button.pIcon01_ico_open {
            margin-right: 2px;
            background: url(./../../../lib/jqueryZtree/3.5.12/css/zTreeStyle/img/zTreeStandard.png) no-repeat scroll -110px -32px transparent;
            vertical-align: top;
            *vertical-align: middle
        }

        .ztree li span.button.pIcon01_ico_close {
            margin-right: 2px;
            background: url(./../../../lib/jqueryZtree/3.5.12/css/zTreeStyle/img/zTreeStandard.png) no-repeat scroll -110px -32px transparent;
            vertical-align: top;
            *vertical-align: middle
        }

        .ztree > li > span.button.chk.checkbox_false_full {
            display: none;
        }
    </style>

</head>
<body>
<div id="content" class="row-fluid easyui-layout" data-options="fit:true" style="height:100%;">
    <div data-options="region:'west',title:'图纸列表',collapsed:false,collapsible:true,split:true"
         style="height:100%;width:20%">
        <div id="tuzhiTree" class="ztree"></div>
    </div>
    <div data-options="region:'center'" style="height:100%;width:80%">
        <div class="layui-tab" lay-allowClose="true" lay-filter="demo" style="height:100%;">
            <ul class="layui-tab-title">
            </ul>
            <div class="layui-tab-content">
            </div>
        </div>
    </div>
</div>
<script src="../../../static/js/main.js"></script>
<script>
    layui.use([
        'configure',
        'ztree',
        'configureCom',
        'checkDrawing',
        'sessionFun',
        'bluebird'
    ], function () {
        var configure = layui.configure;
        var ztree = layui.ztree;
        var configureCom = layui.configureCom;
        var checkDrawing = layui.checkDrawing;
        var sessionFun = layui.sessionFun;
        //获得 当前审查专业对象
        var expertObj = sessionFun.get(configure.SESSION_EXPERT_DATA);
        //单位工程id
        var singleProjectId = configureCom.GetQueryString('singleProjectId');
        //当前选择的专业的Id
        var spcId = expertObj.speciatyId;
        //要打开的图纸的Id;
        var drawingId = expertObj.drawingId;
        //ztree初始化
        checkDrawing.getTree({singleProjectId: singleProjectId}).then(function (res) {
            //将数据格式转变，自定义第二级图标
            var showNode;//默认打开的节点
            $(res.result).each(function (index, item) {
                if (item.id == spcId) {
                    res.result[index].open = true;//打开当前专业节点
                    $.each(item.children, function (s, k) {
                        if (k.id == drawingId) {
                            showNode = k;
                            showDrawing(showNode);
                        }
                    })
                }
                $(item.children).each(function (i, p) {
                    if (p.children.length > 0) {
                        p.iconSkin = 'pIcon01';
                    }
                })
            });
            ztree.param.idKey = 'id';//父级id
            ztree.param.idKey = 'parentId';//子级中与父级id关联
            ztree.param.rootPId = '1';//根节点id
            ztree.init('tuzhiTree', showNode, res.result);
        });
        ztree.param.onClick = function (event, treeId, treeNode) {
            if (treeNode.level >= 1) {
                //如果是图纸，则打开图纸
                showDrawing(treeNode);
            }
        };

        //打开新标签页处理函数
        function showDrawing(obj) {
            //获取打开图纸模块地址
            // var tabUrl = expertObj.specId === obj.speciatyId ? configure.EXPERT_DRAWING_HTML : configure.EXPERT_DRAWING_READ_HTML;
            var tabUrl = configure.EXPERT_DRAWING_ONLY_HTML;
            //将点击的图纸信息存入session
            sessionFun.set(configure.SESSION_DRAWING_DATA, obj);
            //这时会判断右侧.layui-tab-title属性下的有lay-id属性的li的数目，即已经打开的tab项数目
            if ($('.layui-tab-title li[lay-id]').length <= 0) {
                //如果比零小，则直接打开新的tab项
                ztree.tabAdd(
                    tabUrl,     //图纸列表
                    obj.id,     //图纸id
                    obj.name    //图纸名称
                );
            } else {
                //否则判断该tab项是否以及存在
                var isData = false; //初始化一个标志，为false说明未打开该tab项 为true则说明已有
                $.each($('.layui-tab-title li[lay-id]'), function () {
                    //如果点击左侧菜单栏所传入的id 在右侧tab项中的lay-id属性可以找到，则说明该tab项已经打开
                    if (parseInt($(this).attr('lay-id')) === obj.id) {
                        isData = true;
                        return false;
                    }
                });
                if (!isData) {
                    //标志为false 新增一个tab项
                    ztree.tabAdd(
                        tabUrl,     //图纸列表
                        obj.id,     //图纸id
                        obj.name    //图纸名称
                    );
                }
            }
            //最后不管是否新增tab，最后都转到要打开的选项页面上
            ztree.tabChange(obj.id);
        }

        window.removeObject = function () {
            if ($('.layui-show').length > 0) {
                $('.layui-show').remove();
            }
        }
    })

</script>
</body>
</html>